package com.example.demo.job;

import java.util.Date;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import com.dangdang.ddframe.job.executor.ShardingContexts;
import com.dangdang.ddframe.job.lite.api.listener.ElasticJobListener;

@Component
public class JobListener implements ElasticJobListener {

	private  final Logger log = LoggerFactory.getLogger(JobListener.class);
	
	private long beginTime = 0;
	@Override
	public void afterJobExecuted(ShardingContexts shardingContexts) {

		long endTime = System.currentTimeMillis();
		log.info("===>{}, JOB END TIME: {},TOTAL CAST: {},current params:{} <===",shardingContexts.getJobName(),
				new Date().toString(), endTime - beginTime,shardingContexts.getJobParameter());
	}

	@Override
	public void beforeJobExecuted(ShardingContexts shardingContexts) {
		beginTime = System.currentTimeMillis();
		log.info("===>{} JOB BEGIN TIME: {} <===",shardingContexts.getJobName(), new Date().toString());

	}

}
